<?php

namespace App\Providers;

use Illuminate\Routing\Router;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;

class RouteServiceProvider extends ServiceProvider
{

    /**
     * This namespace is applied to the controller routes in your routes file.
     *
     * In addition, it is set as the URL generator's root namespace.
     *
     * @var string
     */
    protected $namespace = 'App\Http\Controllers';

    /**
     * Define your route model bindings, pattern filters, etc.
     *
     * @param  \Illuminate\Routing\Router $router
     * @return void
     */
    public function boot(Router $router)
    {
        parent::boot($router);

        $router->model('fight', 'App\Http\Models\Fight');
        $router->bind('fight', function ($value, $route) {
            return \App\Http\Models\Fight::where('fid', $value)->first();
        });
        $router->pattern('fid', '[0-9]+');

        $router->model('spaceShare', 'App\Http\Models\SpaceShare');
        $router->bind('spaceShare', function ($value, $route) {
            return \App\Http\Models\SpaceShare::where('SSID', $value)->leftJoin('tcustomer', 'tcustomer.CID', '=', 'tspaceshare.SSCustomerID')->select('tspaceshare.*', 'tcustomer.CMobile', 'tcustomer.CName')->first();
        });
        $router->pattern('SSID', '[0-9]+');

        $router->model('train', 'App\Http\Models\Train');
        $router->bind('train', function ($value, $route) {
            return \App\Http\Models\Train::where('TID', $value)->first();
        });
        $router->pattern('TID', '[0-9]+');

        $router->model('match', 'App\Http\Models\Match');
        $router->bind('match', function ($value, $route) {
            return \App\Http\Models\Match::where('MID', $value)->first();
        });
        $router->pattern('mid', '[0-9]+');
        $router->model('spaceOrder', 'App\Http\Models\spaceOrder');
        $router->bind('spaceOrder', function ($value, $route) {
            return \App\Http\Models\spaceOrder::where('SOID', $value)->first();
        });
        $router->pattern('SOID', '[0-9]+');

    }

    /**
     * Define the routes for the application.
     *
     * @param  \Illuminate\Routing\Router $router
     * @return void
     */
    public function map(Router $router)
    {
        $router->group(['namespace' => $this->namespace], function ($router) {
            require app_path('Http/routes.php');
        });
    }

}
